package minijava.Parser;

import minijava.Parser.Fontes.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 *
 * @author schwarz
 * @author brunobp
 */
public class Teste {


   public static void main(String[] args)
   {

           BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           String fileName = null;
           System.out.println("Por padrao, os arquivos se encontram em: src/minijava/SourceCodes/");
           System.out.println("Para outro caminho, digite o caminho levando em consideracao o ponto de partida o diretorio padrao");
           System.out.print("\n\tDigite o nome do arquivo:\t");
           try
           {
               fileName = in.readLine();

           }catch(IOException e){
               System.out.println(e.getMessage());
               System.exit(1);
           }

           System.out.println("\n");
           File source = new File("src/minijava/SourceCodes/" + fileName);
           FileInputStream sourceStream = null;
           try
           {
              sourceStream = new FileInputStream(source);
           }
           catch(FileNotFoundException e)
           {
               //System.out.println("Arquivo nao encontrado");
               System.out.println("Arquivo " + source.getAbsolutePath() + " nao encontrado");
               //e.printStackTrace(System.err);
              System.exit(1);
           }
           

           Analisador analiser = new Analisador(sourceStream);
           //Analisador analiser = new Analisador(System.in);
           Token t;
           int oldLine = 0, oldColumn = 0;
           boolean stop = false;
           while(!stop)
           {
              t = Analisador.getNextToken();
              if((t.endColumn == oldColumn) && (t.endLine == oldLine) && (t.kind == 0))
              {
                  stop = true;
              }
              else
              {
                  oldLine = t.endLine;
                  oldColumn = t.endColumn;
                  System.out.println("Token: "+ t + "; Tipo: " + t.kind);
              }
           }
   }

}

